<?php

namespace app\admin\model\allclass;

use think\Model;


class Tags extends Model
{
    // 表名
    protected $name = 'tags';
    
    // 自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    // 定义时间戳字段名
    protected $createTime = 'createtime';
    protected $updateTime = false;
    protected $deleteTime = false;

    // 追加属性
    protected $append = [

    ];

    public function get_tags($tags)
    {
        $str = str_replace("#","",$tags);
        $ids = explode(',',$str);
        $tags = collection(model("\app\admin\model\allclass\Tags")->where(['id'=>['in',$ids]])->column('name','id'))->toArray();
        return $tags;
    }

    //获取分类列表
    public function getTagsList(){
		return collection(self::where('status', 0)->order('id asc')->select())->toArray();
	}

    //获取分类名称
    public function gettagsInfo($data = array()){

        if(empty($data)){
            return false;
        }
        $list = array();
        //判断是否多行
        if(strstr($data, ',')){
            $classids = array_filter(explode(',',$data));
            foreach($classids as $key=>$value){
                $list[$key]['id'] = $value;
                $list[$key]['name'] = self::where('id',$value)->value('name');
            }
        }else{
            $list[0]['id'] = $data;
            $list[0]['name'] = self::where('id',$data)->value('name');
        }

        return $list;
       
    }

    /**
    * 查询标签详情
    */
    public static function getTagName($data = ''){

        if(empty($data)){
           return false;
        }
        
        $counts = self::where('name', $data['name'])->where(array('status' => array('NEQ', 9)))->count();
        if($counts > 0){
            return false;
        }

        return true;

    }

    /**
    * ID查询标签详情
    */
    public static function getTagNameByID($id = ''){

        if(empty($id)){
           return false;
        }

        $name = self::where('id',$id)->value('name');
        return $name;

    }

}
